]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
notificationDaemon: Match app based on WM_CLASS
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 9 Apr 2012 01:39:59 +0000 (22:39 -0300)
committerJasper St. Pierre <jstpierre@mecheye.net>
Fri, 27 Apr 2012 19:49:18 +0000 (15:49 -0400)
Most tray applets won't have an associated window in the same PID. We
need to fall back to the WM_CLASS in this case.

https://bugzilla.gnome.org/show_bug.cgi?id=673761

js/ui/notificationDaemon.js
src/shell-app-system.c
src/shell-app-system.h
src/shell-window-tracker.c

index f474fbefd6074f086f3ac25eb0d2c4f86c08cf6f..5a20e7c7b8307b931d2539242bea834939105be0 100644 (file)
@@ -578,11 +578,27 @@ const Source = new Lang.Class({
         return true;
     },
 
+    _getApp: function() {
+        let app;
+
+        app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid);
+        if (app != null)
+            return app;
+
+        if (this.trayIcon) {
+            app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wmclass);
+            if (app != null)
+                return app;
+        }
+
+        return null;
+    },
+
     _setApp: function() {
         if (this.app)
             return;
 
-        this.app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid);
+        this.app = this._getApp();
         if (!this.app)
             return;
 
index 2528e9f67f04078c43adbdbe988621866fa8dcc6..a7d1441566d92fa62150284daeeab4cf78a49992 100644 (file)
@@ -608,6 +608,42 @@ shell_app_system_lookup_heuristic_basename (ShellAppSystem *system,
   return NULL;
 }
 
+/**
+ * shell_app_system_lookup_wmclass:
+ * @system: a #ShellAppSystem
+ * @wmclass: A WM_CLASS value
+ *
+ * Find a valid application corresponding to a WM_CLASS value.
+ *
+ * Returns: (transfer none): A #ShellApp for @wmclass
+ */
+ShellApp *
+shell_app_system_lookup_wmclass (ShellAppSystem *system,
+                                 const char     *wmclass)
+{
+  char *canonicalized;
+  char *desktop_file;
+  ShellApp *app;
+
+  if (wmclass == NULL)
+    return NULL;
+
+  canonicalized = g_ascii_strdown (wmclass, -1);
+
+  /* This handles "Fedora Eclipse", probably others.
+   * Note g_strdelimit is modify-in-place. */
+  g_strdelimit (canonicalized, " ", '-');
+
+  desktop_file = g_strconcat (canonicalized, ".desktop", NULL);
+
+  app = shell_app_system_lookup_heuristic_basename (system, desktop_file);
+
+  g_free (canonicalized);
+  g_free (desktop_file);
+
+  return app;
+}
+
 /**
  * shell_app_system_get_all:
  * @system:
index c26b72859d99359935b97ba1d4df0237d99ebed6..b76c6425f179c12e2f43e159fbd55689441a87be 100644 (file)
@@ -49,7 +49,8 @@ ShellApp       *shell_app_system_lookup_app_for_path          (ShellAppSystem  *
                                                                const char      *desktop_path);
 ShellApp       *shell_app_system_lookup_heuristic_basename    (ShellAppSystem  *system,
                                                                const char      *id);
-
+ShellApp       *shell_app_system_lookup_wmclass               (ShellAppSystem *system,
+                                                               const char     *wmclass);
 
 GSList         *shell_app_system_get_all                   (ShellAppSystem  *system);
 
index cc16fe08394b75e304856b080b9d11d67b405c74..2e2ca481e1069fa77a476afee616a79a74cf73af 100644 (file)
@@ -126,30 +126,6 @@ shell_window_tracker_class_init (ShellWindowTrackerClass *klass)
                                                    G_TYPE_NONE, 0);
 }
 
-/**
- * get_appid_from_window:
- *
- * Turn the WM_CLASS property into our best guess at a .desktop file id.
- */
-static char *
-get_appid_from_window (MetaWindow  *window)
-{
-  const char *wmclass;
-  char *appid_guess;
-
-  wmclass = meta_window_get_wm_class (window);
-  if (!wmclass)
-    return NULL;
-
-  appid_guess = g_ascii_strdown (wmclass, -1);
-
-  /* This handles "Fedora Eclipse", probably others.
-   * Note g_strdelimit is modify-in-place. */
-  g_strdelimit (appid_guess, " ", '-');
-
-  return appid_guess;
-}
-
 /**
  * shell_window_tracker_is_window_interesting:
  *
@@ -201,40 +177,6 @@ shell_window_tracker_is_window_interesting (MetaWindow *window)
   return TRUE;
 }
 
-/**
- * get_app_from_window_wmclass:
- *
- * Looks only at the given window, and attempts to determine
- * an application based on WM_CLASS.  If one can't be determined,
- * return %NULL.
- *
- * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
- */
-static ShellApp *
-get_app_from_window_wmclass (MetaWindow  *window)
-{
-  ShellApp *app;
-  ShellAppSystem *appsys;
-  char *wmclass;
-  char *with_desktop;
-
-  appsys = shell_app_system_get_default ();
-  wmclass = get_appid_from_window (window);
-
-  if (!wmclass)
-    return NULL;
-
-  with_desktop = g_strjoin (NULL, wmclass, ".desktop", NULL);
-  g_free (wmclass);
-
-  app = shell_app_system_lookup_heuristic_basename (appsys, with_desktop);
-  if (app != NULL)
-    g_object_ref (app);
-  g_free (with_desktop);
-
-  return app;
-}
-
 /**
  * get_app_from_window_group:
  * @monitor: a #ShellWindowTracker
@@ -328,9 +270,12 @@ static ShellApp *
 get_app_for_window (ShellWindowTracker    *tracker,
                     MetaWindow            *window)
 {
+  ShellAppSystem *app_system;
   ShellApp *result = NULL;
   const char *startup_id;
 
+  app_system = shell_app_system_get_default ();
+
   /* First, we check whether we already know about this window,
    * if so, just return that.
    */
@@ -351,7 +296,8 @@ get_app_for_window (ShellWindowTracker    *tracker,
   /* Check if the app's WM_CLASS specifies an app; this is
    * canonical if it does.
    */
-  result = get_app_from_window_wmclass (window);
+  result = shell_app_system_lookup_wmclass (app_system,
+                                            meta_window_get_wm_class (window));
   if (result != NULL)
     return result;